issue #340: do not apply the choice's maxOccurs bound to the chosen element's items count#345
Open
aldenw wants to merge 1 commit into
Open
Conversation
… chosen element's items count The choice's maxOccurs attribute bounds the number of times the choice group may repeat, not the number of times the chosen element may occur within the group. When the element inside the choice defines its own maxOccurs greater than 1 (or unbounded), the generated setter/adder wrongly rejected any content with more items than the choice's maxOccurs (usually 1), even though the element's own maxOccurs allows them. The element's items count is already constrained by its own maxOccurs rule, so the ChoiceMaxOccursRule now skips the count check in that case.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #340
Problem
When an element inside a
choicedefines its ownmaxOccursgreater than 1, the generated setter/adder wrongly applies the choice'smaxOccurs(usually the default, 1) to the element's items count:generates:
The first check makes the second unreachable: passing more than 1 item throws, even though the schema allows up to 5. Per XSD semantics, the choice's
maxOccursbounds how many times the choice group may repeat — not how many times the chosen element may occur within it; the element's occurrences are bounded by its ownmaxOccurs.This is the same defect reported in #340 (there with
maxOccurs="unbounded"). We hit it in production against Visa's VROL RTSI WSDL, whoseMarkBatchQueueItemAsReadRequestTypedeclares<choice><element ref="vsi:BatchQueueItemSID" minOccurs="1" maxOccurs="5500"/>...</choice>— the generated SDK rejects marking more than one queue item as read.Note: the test added in #342 could not reproduce the issue because in
odigeo.wsdlthechoiceitself carriesmaxOccurs="unbounded", whichMaxOccursRule::testConditions()already skips. The bug appears when the choice'smaxOccursis numeric (e.g. the default 1) while the child element's ownmaxOccursis greater than 1 or unbounded.Fix
ChoiceMaxOccursRulenow skips the items-count check when the element's ownmaxOccursallows more than one occurrence — in that case the element's items count is already (and correctly) constrained by its ownmaxOccursrule. When the element may occur at most once per group repetition, the behavior is unchanged: the choice's bound is applied as before, and the mutual-exclusionchoicevalidation is untouched.This required removing the
finalkeyword fromMaxOccursRule::testConditions()so the subclass can override it.Tests
ItemsChoiceTypecomplex type totests/resources/unit_tests.wsdlreproducing the shape above (element refs withminOccurs="1" maxOccurs="5"inside a default-occurrence choice) and regeneratedparsed_unit_tests_{none,start}.json(additive only).StructTest::testStructItemsChoiceTypeFromUnitTestsasserts the generated file contains themaxOccurs(5)check and nochoiceMaxOccurs(1)items-count check.ChoiceMaxOccursRuleTestasserts at runtime that: several items pass (set and add), more than 5 items still throws (maxOccurs), and setting the other choice property still throws (choice constraint intact).All new tests fail on
developwithout thesrcchange. No other expected generated file changes: no existing fixture combines a numeric-maxOccurschoice with a multi-occurrence child.